congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ProtobufIOUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
ProtobufIOUtil
in
io.protostuff

Best Java code snippets using io.protostuff.ProtobufIOUtil (Showing top 20 results out of 315)

origin: protostuff/protostuff

@Override
protected <T> byte[] toByteArray(T message, Schema<T> schema)
{
  return ProtobufIOUtil.toByteArray(message, schema, buf());
}
origin: protostuff/protostuff

@Override
protected <T> void mergeFrom(byte[] data, int offset, int length,
    T message, Schema<T> schema) throws IOException
{
  ProtobufIOUtil.mergeFrom(data, offset, length, message, schema);
}
origin: protostuff/protostuff

/**
 * Creates a protobuf pipe from a byte array.
 */
public static Pipe newPipe(byte[] data)
{
  return newPipe(data, 0, data.length);
}
origin: protostuff/protostuff

static <T> void protobufRoundTrip(T message, Schema<T> schema,
    Pipe.Schema<T> pipeSchema) throws Exception
{
  byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf());
  ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf);
  byte[] smile = SmileIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, false);
  byte[] smileFromStream = SmileIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobufStream), pipeSchema, false);
  assertTrue(Arrays.equals(smile, smileFromStream));
  T parsedMessage = schema.newMessage();
  SmileIOUtil.mergeFrom(smile, parsedMessage, schema, false);
  SerializableObjects.assertEquals(message, parsedMessage);
  ByteArrayInputStream smileStream = new ByteArrayInputStream(smile);
  byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray(
      SmileIOUtil.newPipe(smile, 0, smile.length, false), pipeSchema, buf());
  byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray(
      SmileIOUtil.newPipe(smileStream, false), pipeSchema, buf());
  assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream));
  assertTrue(Arrays.equals(protobufRoundTrip, protobuf));
}
origin: protostuff/protostuff

static void verifyProtobuf(PojoWithInts p) throws IOException
{
  Schema<PojoWithInts> schema = PojoWithInts.getSchema();
  byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf());
  PojoWithInts pFromByteArray = new PojoWithInts();
  ProtobufIOUtil.mergeFrom(data, pFromByteArray, schema);
  assertEquals(p, pFromByteArray);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ProtobufIOUtil.writeTo(out, p, schema, buf());
  byte[] dataFromStream = out.toByteArray();
  assertTrue(Arrays.equals(data, dataFromStream));
  ByteArrayInputStream in = new ByteArrayInputStream(data);
  PojoWithInts pFromStream = new PojoWithInts();
  ProtobufIOUtil.mergeFrom(in, pFromStream, schema);
  assertEquals(p, pFromStream);
}
origin: protostuff/protostuff

public void testProtobuf() throws Exception
{
  Schema<Zoo> schema = RuntimeSchema.getSchema(Zoo.class);
  Zoo p = filledZoo();
  byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf());
  // System.err.println("protobuf: " + data.length);
  Zoo p2 = new Zoo();
  ProtobufIOUtil.mergeFrom(data, p2, schema);
  assertEquals(p, p2);
  List<Zoo> list = new ArrayList<Zoo>();
  list.add(p);
  list.add(p2);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ProtobufIOUtil.writeListTo(out, list, schema, buf());
  byte[] listData = out.toByteArray();
  ByteArrayInputStream in = new ByteArrayInputStream(listData);
  List<Zoo> parsedList = ProtobufIOUtil.parseListFrom(in, schema);
  assertEquals(list, parsedList);
}
origin: protostuff/protostuff

public void testNestedOverflow()
{
  final int bufSize = 256;
  final Bar bar = new Bar();
  // reserve 3 bytes:
  // 1st: tag
  // 2nd and 3rd: delimited length (greater than 127 takes to more than one byte)
  int repeat = bufSize - 3;
  bar.setSomeString(repeatChar('a', repeat));
  byte[] data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize));
  assertEquals(bufSize, data.length);
  // additional size will be:
  // 1 (tag)
  // 1 (delimiter)
  // 1 + 1 = tag + value (10)
  // 1 + 1 + 3 = tag + delim + value ("baz")
  // 1 + 1 = tag + value (15)
  // =====
  // 11
  bar.setSomeBaz(new Baz(10, "baz", 15l));
  data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize));
  assertEquals(bufSize + 11, data.length);
  final Bar parsedBar = new Bar();
  ProtobufIOUtil.mergeFrom(data, parsedBar, parsedBar.cachedSchema());
  assertEquals(bar, parsedBar);
}
origin: protostuff/protostuff

public void testProtobuf() throws Exception
{
  Schema<Entity> schema = RuntimeSchema.getSchema(Entity.class);
  Entity p = filledEntity();
  byte[] data = ProtobufIOUtil.toByteArray(p, schema,
      LinkedBuffer.allocate(512));
  Entity p2 = new Entity();
  ProtostuffIOUtil.mergeFrom(data, p2, schema);
  assertEquals(p, p2);
  List<Entity> list = new ArrayList<Entity>();
  list.add(p);
  list.add(p2);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ProtobufIOUtil.writeListTo(out, list, schema, buf());
  byte[] listData = out.toByteArray();
  ByteArrayInputStream in = new ByteArrayInputStream(listData);
  List<Entity> parsedList = ProtobufIOUtil.parseListFrom(in, schema);
  assertEquals(list, parsedList);
}
origin: protostuff/protostuff

public void testInheritanceProtobuf() throws IOException
{
  if (skipTests)
  {
    System.err
        .println("RuntimeSchema.MORPH_NON_FINAL_POJOS was not enabled.");
    return;
  }
  System.err.println("executing inheritance test for protobuf ... ");
  Schema<InputSystem> schema = RuntimeSchema.getSchema(InputSystem.class);
  InputSystem sys = new InputSystem();
  KeyBoard kb = new KeyBoard();
  Mouse ms = new Mouse();
  kb.setName("Test");
  kb.setNumberOfKeys(10);
  ms.setName("Test1");
  ms.setNumberOfButtons(2);
  List<InputDevice> devices = new ArrayList<InputDevice>();
  devices.add(ms);
  devices.add(kb);
  sys.setInputDevices(devices);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ProtobufIOUtil.writeTo(out, sys, schema, buf());
  byte[] listData = out.toByteArray();
  InputSystem deserSystem = new InputSystem();
  ByteArrayInputStream in = new ByteArrayInputStream(listData);
  ProtobufIOUtil.mergeFrom(in, deserSystem, schema, buf());
  assertEquals(sys, deserSystem);
}
origin: protostuff/protostuff

@Benchmark
public void generated_serialize_1_int_field() throws Exception
{
  try
  {
    ProtobufIOUtil.writeTo(buffer, generatedInt1, generatedInt1Schema);
  }
  finally
  {
    buffer.clear();
  }
}
origin: protostuff/protostuff

@Override
protected <T> void mergeDelimitedFrom(InputStream in, T message, Schema<T> schema)
    throws IOException
{
  ProtobufIOUtil.mergeDelimitedFrom(in, message, schema);
}
origin: protostuff/protostuff

static <T> void protobufRoundTrip(T message, Schema<T> schema,
    Pipe.Schema<T> pipeSchema) throws Exception
{
  byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf());
  ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf);
  byte[] yaml = YamlIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, buf());
  byte[] yamlFromStream = YamlIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf());
  assertTrue(yaml.length == yamlFromStream.length);
  String strYaml = STRING.deser(yaml);
  String strYamlFromStream = STRING.deser(yamlFromStream);
  assertEquals(strYaml, strYamlFromStream);
}
origin: protostuff/protostuff

public void testProtobuf() throws Exception
{
  Schema<Payment> schema = RuntimeSchema.getSchema(Payment.class);
  Payment p = filledPayment();
  byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf());
  Payment p2 = new Payment();
  ProtobufIOUtil.mergeFrom(data, p2, schema);
  /*
   * System.err.println(p2.getId()); System.err.println(p2.getBd()); System.err.println(p2.getBi());
   * System.err.println(p2.getBdList()); System.err.println(p2.getBiList());
   */
  assertEquals(p, p2);
  List<Payment> list = new ArrayList<Payment>();
  list.add(p);
  list.add(p2);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ProtobufIOUtil.writeListTo(out, list, schema, buf());
  byte[] listData = out.toByteArray();
  ByteArrayInputStream in = new ByteArrayInputStream(listData);
  List<Payment> parsedList = ProtobufIOUtil.parseListFrom(in, schema);
  assertEquals(list, parsedList);
}
origin: protostuff/protostuff

public void testNestedLarge()
{
  final int bufSize = 256;
  final Bar bar = new Bar();
  // nested message size will be:
  // 1 + 1 = tag + value (10)
  // 1 + 1 + 125 = tag + delim + value ("baz")
  // 1 + 1 = tag + value (15)
  // =====
  // 131
  bar.setSomeBaz(new Baz(10, repeatChar('b', 125), 15l));
  // size will be:
  // 1 (tag)
  // 2 (delimited length) (nested message size is greater than 127)
  // 131 (nested message size)
  // =====
  // 134
  byte[] data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize));
  assertEquals(134, data.length);
  final Bar parsedBar = new Bar();
  ProtobufIOUtil.mergeFrom(data, parsedBar, parsedBar.cachedSchema());
  assertEquals(bar, parsedBar);
}
origin: protostuff/protostuff

@Benchmark
public void runtime_sparse_serialize_10_int_fields() throws Exception
{
  try
  {
    ProtobufIOUtil.writeTo(buffer, sparseInt10, sparseInt10RuntimeSchema);
  }
  finally
  {
    buffer.clear();
  }
}
origin: protostuff/protostuff

@Override
protected <T> void mergeDelimitedFrom(InputStream in, T message, Schema<T> schema)
    throws IOException
{
  ProtobufIOUtil.mergeDelimitedFrom(in, message, schema);
}
origin: protostuff/protostuff

@Override
protected <T> void mergeFrom(byte[] data, int offset, int length,
    T message, Schema<T> schema) throws IOException
{
  ProtobufIOUtil.mergeFrom(data, offset, length, message, schema);
}
origin: protostuff/protostuff

@Override
protected <T> void roundTrip(T message, Schema<T> schema,
    Pipe.Schema<T> pipeSchema) throws Exception
{
  byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf());
  ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf);
  byte[] protostuff = ProtostuffIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length),
      pipeSchema, buf());
  byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray(
      ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf());
  assertTrue(Arrays.equals(protostuff, protostuffFromStream));
  T parsedMessage = schema.newMessage();
  ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema);
  SerializableObjects.assertEquals(message, parsedMessage);
  ByteArrayInputStream protostuffStream = new ByteArrayInputStream(
      protostuff);
  byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray(
      ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length),
      pipeSchema, buf());
  byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray(
      ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, buf());
  assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream));
  assertTrue(Arrays.equals(protobufRoundTrip, protobuf));
}
origin: protostuff/protostuff

@Override
protected <T> byte[] toByteArray(T message, Schema<T> schema)
{
  return ProtobufIOUtil.toByteArray(message, schema, buf());
}
origin: protostuff/protostuff

@Benchmark
public void generated_serialize_10_int_field() throws Exception
{
  try
  {
    ProtobufIOUtil.writeTo(buffer, generatedInt10, generatedInt10Schema);
  }
  finally
  {
    buffer.clear();
  }
}
io.protostuffProtobufIOUtil

Javadoc

Protobuf ser/deser util for messages/objects.

Most used methods

  • toByteArray
  • mergeFrom
  • newPipe
    Creates a protobuf pipe from a byte array.
  • writeTo
    Serializes the message into an OutputStream using the given schema.
  • mergeDelimitedFrom
    Merges the message (delimited) from the InputStream using the given schema. The delimited message si
  • optMergeDelimitedFrom
    Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and t
  • parseListFrom
    Parses the messages (delimited) from the InputStream using the given schema.
  • writeDelimitedTo
    Serializes the message, prefixed with its length, into an OutputStream.
  • writeListTo
    Serializes the messages (delimited) into an OutputStream using the given schema.
  • optWriteDelimitedTo
    Optimal writeDelimitedTo - The varint32 prefix is written to the buffer instead of directly writing

Popular in Java

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • setContentView (Activity)
  • onCreateOptionsMenu (Activity)
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now