Java Code Examples for io.protostuff.Output#writeUInt32()
The following examples show how to use
io.protostuff.Output#writeUInt32() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectSchema.java From protostuff with Apache License 2.0 | 6 votes |
private static void writeComponentTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy, Class<?> componentType, int dimensions) throws IOException { strategy.writeArrayIdTo(output, componentType); // write the length of the array output.writeUInt32(ID_ARRAY_LEN, ((Object[])value).length, false); // write the dimensions of the array output.writeUInt32(ID_ARRAY_DIMENSION, dimensions, false); if (output instanceof StatefulOutput) { // update using the derived schema. ((StatefulOutput) output).updateLast(strategy.ARRAY_SCHEMA, currentSchema); } strategy.ARRAY_SCHEMA.writeTo(output, value); }
Example 2
Source File: ArraySchemas.java From protostuff with Apache License 2.0 | 5 votes |
@Override public void writeTo(Output output, Object value) throws IOException { CharSequence[] array = (CharSequence []) value; output.writeInt32(ID_ARRAY_LEN, array.length, false); int nullCount = 0; for (int i = 0, len = array.length; i < len; i++) { CharSequence v = array[i]; if (v != null) { if (nullCount != 0) { output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false); nullCount = 0; } output.writeString(ID_ARRAY_DATA, v, true); } else if (allowNullArrayElement) { nullCount++; } } // if last element is null if (nullCount != 0) output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false); }
Example 3
Source File: IncrementalIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override protected <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException { int id; BaseHS<T> wrapper = getBaseHS(clazz, true); // wait till everything is completely set while (0 == (id = wrapper.id)) LockSupport.parkNanos(1); output.writeUInt32(fieldNumber, id, false); return wrapper; }
Example 4
Source File: IncrementalIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override protected void writeMapIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException { int id; RuntimeMapFactory factory = getRuntimeMapFactory(clazz); // wait till everything is completely set while (0 == (id = factory.id)) LockSupport.parkNanos(1); output.writeUInt32(fieldNumber, id, false); }
Example 5
Source File: IncrementalIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> tryWriteDelegateIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException { final RegisteredDelegate<T> rd = (RegisteredDelegate<T>) delegateMapping.get( clazz); if (rd == null) return null; output.writeUInt32(fieldNumber, rd.id, false); return rd; }
Example 6
Source File: ArraySchemas.java From protostuff with Apache License 2.0 | 5 votes |
@Override public void writeTo(Output output, Object value) throws IOException { BigInteger[] array = (BigInteger[]) value; output.writeInt32(ID_ARRAY_LEN, array.length, false); int nullCount = 0; for (int i = 0, len = array.length; i < len; i++) { BigInteger v = array[i]; if (v != null) { if (nullCount != 0) { output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false); nullCount = 0; } output.writeByteArray(ID_ARRAY_DATA, v.toByteArray(), true); } else if (allowNullArrayElement) { nullCount++; } } // if last element is null if (nullCount != 0) output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false); }
Example 7
Source File: ArraySchema.java From protostuff with Apache License 2.0 | 5 votes |
static void writeObjectTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy) throws IOException { final Class<?> clazz = value.getClass(); int dimensions = 1; Class<?> componentType = clazz.getComponentType(); while (componentType.isArray()) { dimensions++; componentType = componentType.getComponentType(); } strategy.writeArrayIdTo(output, componentType); // write the length of the array output.writeUInt32(ID_ARRAY_LEN, ((Object[])value).length, false); // write the dimensions of the array output.writeUInt32(ID_ARRAY_DIMENSION, dimensions, false); if (output instanceof StatefulOutput) { // update using the derived schema. ((StatefulOutput) output).updateLast(strategy.ARRAY_SCHEMA, currentSchema); } strategy.ARRAY_SCHEMA.writeTo(output, value); }
Example 8
Source File: ExplicitIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override protected void writeCollectionIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException { final RegisteredCollectionFactory factory = collectionMapping.get(clazz); if (factory == null) throw new UnknownTypeException("collection: " + clazz); output.writeUInt32(fieldNumber, factory.id, false); }
Example 9
Source File: ExplicitIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws IOException { final BaseHS<T> wrapper = (BaseHS<T>) pojoMapping.get(message.getClass()); if (wrapper == null) throw new UnknownTypeException("pojo: " + message.getClass()); output.writeUInt32(fieldNumber, wrapper.id, false); // TODO allow the wrapper to return an override schema? return message.cachedSchema(); }
Example 10
Source File: ArraySchemas.java From protostuff with Apache License 2.0 | 5 votes |
@Override protected void transfer(Pipe pipe, Input input, Output output) throws IOException { if (ID_ARRAY_LEN != input .readFieldNumber(pipeSchema.wrappedSchema)) throw new ProtostuffException("Corrupt input."); final int len = input.readInt32(); // write it back output.writeInt32(ID_ARRAY_LEN, len, false); for (int i = 0, nullCount = 0; i < len;) { switch (input.readFieldNumber(pipeSchema.wrappedSchema)) { case ID_ARRAY_DATA: i++; output.writeObject(ID_ARRAY_DATA, pipe, hs.getPipeSchema(), true); break; case ID_ARRAY_NULLCOUNT: nullCount = input.readUInt32(); i += nullCount; output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false); break; default: throw new ProtostuffException("Corrupt input."); } } if (0 != input.readFieldNumber(pipeSchema.wrappedSchema)) throw new ProtostuffException("Corrupt input."); }
Example 11
Source File: ExplicitIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException { final BaseHS<T> wrapper = (BaseHS<T>) pojoMapping.get(clazz); if (wrapper == null) throw new UnknownTypeException("pojo: " + clazz); output.writeUInt32(fieldNumber, wrapper.id, false); return wrapper; }
Example 12
Source File: ExplicitIdStrategy.java From protostuff with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws IOException { final int id = input.readUInt32(); final BaseHS<T> wrapper = (BaseHS<T>) pojos.get(id); if (wrapper == null) throw new UnknownTypeException("pojo id: " + id + " (Outdated registry)"); output.writeUInt32(fieldNumber, id, false); return wrapper; }
Example 13
Source File: RuntimeUnsafeFieldFactory.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException { output.writeUInt32(number, input.readUInt32(), repeated); }
Example 14
Source File: RuntimeUnsafeFieldFactory.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void writeTo(Output output, int number, Character value, boolean repeated) throws IOException { output.writeUInt32(number, value.charValue(), repeated); }
Example 15
Source File: SampleDelegates.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void writeTo(Output output, int number, Singleton value, boolean repeated) throws IOException { output.writeUInt32(number, 0, repeated); }
Example 16
Source File: SampleDelegates.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException { output.writeUInt32(number, input.readUInt32(), repeated); }
Example 17
Source File: RuntimeReflectionFieldFactory.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException { output.writeUInt32(number, input.readUInt32(), repeated); }
Example 18
Source File: RuntimeUnsafeFieldFactory.java From protostuff with Apache License 2.0 | 4 votes |
@Override public void writeTo(Output output, int number, Short value, boolean repeated) throws IOException { output.writeUInt32(number, value.shortValue(), repeated); }
Example 19
Source File: ExplicitIdStrategy.java From protostuff with Apache License 2.0 | 4 votes |
@Override protected void transferMapId(Input input, Output output, int fieldNumber) throws IOException { output.writeUInt32(fieldNumber, input.readUInt32(), false); }
Example 20
Source File: PolymorphicMapSchema.java From protostuff with Apache License 2.0 | 4 votes |
static void writeNonPublicMapTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy) throws IOException { final Integer n = __nonPublicMaps.get(value.getClass()); if (n == null) throw new RuntimeException("Unknown collection: " + value.getClass()); final int id = n.intValue(); switch (id) { case ID_EMPTY_MAP: output.writeUInt32(id, 0, false); break; case ID_SINGLETON_MAP: { final Object k, v; try { k = fSingletonMap_k.get(value); v = fSingletonMap_v.get(value); } catch (Exception e) { throw new RuntimeException(e); } output.writeUInt32(id, 0, false); if (k != null) output.writeObject(1, k, strategy.OBJECT_SCHEMA, false); if (v != null) output.writeObject(3, v, strategy.OBJECT_SCHEMA, false); break; } case ID_UNMODIFIABLE_MAP: writeUnmodifiableMapTo(output, value, currentSchema, strategy, id); break; case ID_UNMODIFIABLE_SORTED_MAP: writeUnmodifiableMapTo(output, value, currentSchema, strategy, id); break; case ID_SYNCHRONIZED_MAP: writeSynchronizedMapTo(output, value, currentSchema, strategy, id); break; case ID_SYNCHRONIZED_SORTED_MAP: writeSynchronizedMapTo(output, value, currentSchema, strategy, id); break; case ID_CHECKED_MAP: writeCheckedMapTo(output, value, currentSchema, strategy, id); break; case ID_CHECKED_SORTED_MAP: writeCheckedMapTo(output, value, currentSchema, strategy, id); break; default: throw new RuntimeException("Should not happen."); } }