Skip to content
Permalink
Browse files
Generated most of the marshalling/unmarshalling bits.
  • Loading branch information
chirino committed Aug 31, 2008
1 parent ba7fdf6 commit 79921c2523c56810b7ede1c7ca297cf2606f3fc4
Showing 6 changed files with 585 additions and 102 deletions.
@@ -0,0 +1,86 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.protobuf;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.ExtensionRegistry;

import static org.apache.activemq.protobuf.WireInfo.*;

import java.io.IOException;

abstract public class Message<T> {

protected int memoizedSerializedSize = -1;

static protected void writeGroup(CodedOutputStream output, int tag, Message message) throws IOException {
output.writeTag(tag, WIRETYPE_START_GROUP);
message.writeTo(output);
output.writeTag(tag, WIRETYPE_END_GROUP);
}

static protected void writeMessage(CodedOutputStream output, int tag, Message message) throws IOException {
output.writeTag(tag, WIRETYPE_LENGTH_DELIMITED);
output.writeRawVarint32(message.serializedSize());
message.writeTo(output);
}

static protected <T extends Message> T readGroup(CodedInputStream input, ExtensionRegistry extensionRegistry, int tag, T group) throws IOException {
group.mergeFrom(input, extensionRegistry);
input.checkLastTagWas(makeTag(tag, WIRETYPE_END_GROUP));
return group;
}

static protected <T extends Message> T readMessage(CodedInputStream input, ExtensionRegistry extensionRegistry, T message) throws IOException {
int length = input.readRawVarint32();
int oldLimit = input.pushLimit(length);
message.mergeFrom(input, extensionRegistry);
input.checkLastTagWas(0);
input.popLimit(oldLimit);
return message;
}

static protected int computeGroupSize(int tag, Message message) {
return CodedOutputStream.computeTagSize(tag) * 2 + message.serializedSize();
}

static protected int computeMessageSize(int tag, Message message) {
int t = message.serializedSize();
return CodedOutputStream.computeTagSize(tag) +
CodedOutputStream.computeRawVarint32Size(t)+t;
}


abstract public T mergeFrom(T other);

public T mergeFrom(CodedInputStream input) throws IOException {
return mergeFrom(input, ExtensionRegistry.getEmptyRegistry());
}

abstract public T mergeFrom(CodedInputStream input, ExtensionRegistry extensionRegistry) throws IOException;

abstract public void writeTo(CodedOutputStream output) throws java.io.IOException;

abstract public T clone();

abstract public int serializedSize();

abstract public void clear();

abstract public boolean isInitialized();
}
@@ -0,0 +1,33 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.protobuf;

public class WireInfo {

public static final int WIRETYPE_VARINT = 0;
public static final int WIRETYPE_FIXED64 = 1;
public static final int WIRETYPE_LENGTH_DELIMITED = 2;
public static final int WIRETYPE_START_GROUP = 3;
public static final int WIRETYPE_END_GROUP = 4;
public static final int WIRETYPE_FIXED32 = 5;

public static final int TAG_TYPE_BITS = 3;

public static int makeTag(int fieldNumber, int wireType) {
return (fieldNumber << TAG_TYPE_BITS) | wireType;
}
}
@@ -68,5 +68,9 @@ public String getQName() {
}
}

public boolean isEnum() {
return true;
}


}

0 comments on commit 79921c2

Please sign in to comment.