Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ServiceConfigURLDelegate for protostuff #67

Merged
merged 11 commits into from
Nov 14, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.dubbo.common.serialize.protostuff.delegate;

import io.protostuff.Input;
import io.protostuff.Output;
import io.protostuff.Pipe;
import io.protostuff.WireFormat;
import io.protostuff.runtime.Delegate;

import java.io.IOException;

import org.apache.dubbo.common.url.component.ServiceConfigURL;

/**
* Custom {@link org.apache.dubbo.common.url.component.ServiceConfigURL} delegate
*/
public class ServiceConfigURLDelegate implements Delegate<ServiceConfigURL> {
@Override
public WireFormat.FieldType getFieldType() {
return WireFormat.FieldType.STRING;
}

@Override
public ServiceConfigURL readFrom(Input input) throws IOException {
return (ServiceConfigURL) org.apache.dubbo.common.URL.valueOf(input.readString());
}

@Override
public void writeTo(Output output, int number, ServiceConfigURL value, boolean repeated) throws IOException {
output.writeString(number, value.toFullString(), repeated);
}

@Override
public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException {
output.writeString(number, input.readString(), repeated);
}

@Override
public Class<?> typeClass() {
return ServiceConfigURL.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.common.serialize.protostuff.delegate.SqlDateDelegate;
import org.apache.dubbo.common.serialize.protostuff.delegate.TimeDelegate;
import org.apache.dubbo.common.serialize.protostuff.delegate.TimestampDelegate;
import org.apache.dubbo.common.serialize.protostuff.delegate.ServiceConfigURLDelegate;

import io.protostuff.runtime.DefaultIdStrategy;
import io.protostuff.runtime.RuntimeEnv;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class WrapperUtils {
if (RuntimeEnv.ID_STRATEGY instanceof DefaultIdStrategy) {
((DefaultIdStrategy) RuntimeEnv.ID_STRATEGY).registerDelegate(new TimeDelegate());
((DefaultIdStrategy) RuntimeEnv.ID_STRATEGY).registerDelegate(new TimestampDelegate());
((DefaultIdStrategy) RuntimeEnv.ID_STRATEGY).registerDelegate(new ServiceConfigURLDelegate());
((DefaultIdStrategy) RuntimeEnv.ID_STRATEGY).registerDelegate(new SqlDateDelegate());
}

Expand Down Expand Up @@ -87,6 +89,7 @@ public class WrapperUtils {
WRAPPER_SET.add(Time.class);
WRAPPER_SET.add(Timestamp.class);
WRAPPER_SET.add(java.sql.Date.class);
WRAPPER_SET.add(org.apache.dubbo.common.url.component.ServiceConfigURL.class);

WRAPPER_SET.add(Wrapper.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public abstract class AbstractSerializationTest {
protected URL url = new URL("protocol", "1.1.1.1", 1234);
protected ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

// ================ Primitive Type ================
// ================ Primitive Type ================
protected BigPerson bigPerson;
protected MediaContent mediaContent;

Expand Down Expand Up @@ -383,7 +383,7 @@ public void test_BytesRange() throws Exception {
}
}

// ================ Array Type ================
// ================ Array Type ================

<T> void assertObjectArray(T[] data, Class<T[]> clazz) throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
Expand Down Expand Up @@ -762,7 +762,7 @@ public void test_StringArray_withType() throws Exception {
assertObjectArrayWithType(new String[]{"1", "b"}, String[].class);
}

// ================ Simple Type ================
// ================ Simple Type ================

@Test
public void test_IntegerArray() throws Exception {
Expand Down Expand Up @@ -979,7 +979,7 @@ public void test_LinkedHashMap() throws Exception {
}
}

// ================ Complex Collection Type ================
// ================ Complex Collection Type ================

@Test
public void test_SPersonList() throws Exception {
Expand Down Expand Up @@ -1111,7 +1111,7 @@ public void test_MultiObject_WithType() throws Exception {
}


// abnormal case
// abnormal case

@Test
public void test_MediaContent_badStream() throws Exception {
Expand Down Expand Up @@ -1188,7 +1188,6 @@ public void test_LoopReference() throws Exception {
// ================ final field test ================

@Test
@Disabled
public void test_URL_mutable_withType() throws Exception {
URL data = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue");

Expand Down
Loading